<?php


namespace app\model;


use think\Model;
use think\model\relation\HasMany;
use think\model\relation\HasOne;


class ArticleModel extends Model
{
    protected $table = 'article';
    protected $key = 'id';
    // 设置字段信息
    protected $schema = [
        'id' => 'int',
        'title' => 'varchar',
        'articleContent' => 'text',
        'linkes' => 'char',
        'issueTime' => 'datetime',
        'articleTypeId' => 'int',
        'comtID' => 'int',
        'uid' => 'int',
    ];

    //自动时间戳
    protected $autoWriteTimestamp = 'datetime';
    protected $updateTime = false;
    protected $createTime = 'issueTime';


    // 一对一 用户
    public function articleUser(): HasOne
    {
        return $this->hasOne(Account::class, 'id', 'uid')->bind(['userName']);
    }

    // 一对一 分类
    public function articleType(): HasOne
    {
        return $this->hasOne(articleType::class, 'id', 'articleTypeId')->bind(['typeName']);
    }

    // 一对多 评论
    public function articleDiscuss(): HasMany
    {
        return $this->hasMany(articleDiscuss::class, 'disID', 'articleTypeId');
    }

    // 一对多 点赞
    public function articleLinke(): HasMany
    {
        return $this->hasMany(ArticleLikeModel::class, 'articleId', 'id');
    }

    // 一对多 收藏
    public function articleCollect(): HasMany
    {
        return $this->hasMany(ArticleCollectModel::class, 'articleId', 'id');
    }


}